# 在orders/tasks.py
from celery import shared_task
from django.utils import timezone
from .models import Order

@shared_task
def cancel_unpaid_orders():
    Order.objects.filter(
        status='pending',
        created_at__lt=timezone.now()-timezone.timedelta(minutes=30)
    ).update(status='cancelled')